package com.data.service.extension;

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
public class DatasourceFactory {
    @Autowired
    private ApplicationContext applicationContext;

    public DataSourceExtension getDataSourceExtension(String type) {
        return applicationContext.getBean(type, DataSourceExtension.class);
    }

    public DataSource getDataSource(String beanName) {
        return ((DynamicRoutingDataSource)applicationContext.getBean(DataSource.class)).getDataSource(beanName);
    }
}
